﻿using MEF_Test.Subtitles;

namespace OpenAction.MydraVideoOpenActionContextProvider
{
    using System;
    using System.ComponentModel.Composition;

    using MEF_Test.Bricks.Subtitles;
    using MEF_Test.Contracts;

    using Microsoft.Practices.Prism.Regions;

    /// <summary>
    /// A factory to create instances of <see cref="MydraVideoOpenActionContextProvider"/>.
    /// </summary>
    /// <remarks><see cref="MydraVideoOpenActionContextProvider"/> implements <see cref="IOpenActionContextProvider"/>, which is the contract for all parts which contains the concrete implementation of the business logic for an <see cref="OpenAction"/>.</remarks>
    [Export(typeof(IOpenActionContextProviderFactory))]
    public class MydraVideoOpenActionContextProviderFactory : IOpenActionContextProviderFactory
    {
        /// <summary>
        /// The video renderer to use with the <see cref="MydraVideoOpenActionContextProvider"/> context provider.
        /// </summary>
        private readonly IVideoRendererController _videoRenderer;

        private readonly ISubtitlesProvidersManager _subtitlesProvidersManager;

        private readonly IRegionManager _regionManager;
        private readonly ISubtitleSelectionViewFactory _subtitleSelectionView;
        private readonly ISubtitlesSelectionPageViewModelFactory _subtitleSelectionViewModelFactory;

        /// <summary>
        /// Initializes a new instance of the <see cref="MydraVideoOpenActionContextProviderFactory"/> class.
        /// </summary>
        /// <param name="videoRenderer">The video renderer.</param>
        /// <param name="subtitlesProvidersManager">The subtitles providers manager.</param>
        /// <param name="regionManager">The region manager.</param>
        /// <param name="subtitleSelectionView">The subtitle selection view.</param>
        /// <param name="subtitleSelectionViewModelFactory">The subtitle selection view model factory.</param>
        [ImportingConstructor]
        public MydraVideoOpenActionContextProviderFactory(IVideoRendererController videoRenderer, ISubtitlesProvidersManager subtitlesProvidersManager, IRegionManager regionManager, ISubtitleSelectionViewFactory subtitleSelectionView, ISubtitlesSelectionPageViewModelFactory subtitleSelectionViewModelFactory)
        {
            if (videoRenderer == null)
            {
                throw new ArgumentNullException("videoRenderer");
            }
            if (subtitlesProvidersManager == null)
            {
                throw new ArgumentNullException("subtitlesProvidersManager");
            }
            if (regionManager == null)
            {
                throw new ArgumentNullException("regionManager");
            }
            if (subtitleSelectionView == null) throw new ArgumentNullException("subtitleSelectionView");
            if (subtitleSelectionViewModelFactory == null)
                throw new ArgumentNullException("subtitleSelectionViewModelFactory");

            _videoRenderer = videoRenderer;
            _subtitleSelectionViewModelFactory = subtitleSelectionViewModelFactory;
            _subtitlesProvidersManager = subtitlesProvidersManager;
            _regionManager = regionManager;
            _subtitleSelectionView = subtitleSelectionView;
        }

        /// <summary>
        /// Creates this instance.
        /// </summary>
        /// <returns>An instance of an Open-action context provider.</returns>
        public IOpenActionContextProvider Create()
        {
            return new MydraVideoOpenActionContextProvider(_videoRenderer, _subtitlesProvidersManager, _regionManager, _subtitleSelectionView, _subtitleSelectionViewModelFactory);
        }
    }
}